package com.masterrabbit.gmh.controller;

import com.masterrabbit.gmh.domain.Reviews;
import com.masterrabbit.gmh.mapper.MerchantsMapper;
import com.masterrabbit.gmh.service.ReviewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/reviews")
public class ReviewsController {

    @Autowired
    private ReviewsService reviewsService;

    @Autowired
    private MerchantsMapper merchantsMapper;

    @GetMapping("selectReviews")
    public List<Reviews> selectReviews(Integer userMerchantId){
        List<Reviews> reviews=new ArrayList<>();
        List<Reviews> reviews1 = reviewsService.selectByUserMerchantId(userMerchantId);
        for (Reviews review : reviews1) {
            List<String> strings = merchantsMapper.selectByProductId(review.getImageId());
            review.setImgUrls(strings);
            reviews.add(review);
        }
        return reviews;
    }
}
